package ar.com.spsolutions.splilabrary.view.pages.book;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;

import ar.com.spsolutions.splibrary.book.Book;

public class BookDetailsContainer extends Panel {

    private static final long serialVersionUID = 2644760152896499006L;

    private List<Book> books;

    public BookDetailsContainer(final String id, final List<Book> books) {
        super(id);
        this.books = books;
        addList();
    }

    public BookDetailsContainer(final String id) {
        this(id, new ArrayList<Book>());
    }

    private void addList() {
        final ListView<Book> list = new ListView<Book>("book", getBooks()) {

            private static final long serialVersionUID = 3634224977916608964L;

            @Override
            protected void populateItem(final ListItem<Book> item) {
                final BookDetail bookDetail = new BookDetail("bookDetail", item.getModelObject());
                item.add(bookDetail);
            }
        };
        this.add(list);
    }

    public List<Book> getBooks() {
        if (books == null) {
            return new ArrayList<Book>();
        }
        return books;
    }

    public void setBooks(final List<Book> books) {
        this.books = books;
    }

}
